<template>
	<view>
		<view class="my-content uni-column">
			<view class="uni-column">
				<view class="platform">
					OKEx
				</view>
				<uni-list>
					<uni-list-item v-for="(item,index ) in accounts" :key="index" :title="item.name" :show-badge="item.actived"
					 badge-text="✓" :show-arrow="false" @click="changeAcount(item.id)" ></uni-list-item>
				</uni-list>
			</view>

		</view>
	</view>
</template>

<script>
	var _self
	import uniList from "@/components/uni-list/uni-list.vue"
	import uniListItem from "@/components/uni-list-item/uni-list-item.vue"
	export default {
		components: {
			uniList,
			uniListItem
		},
		data() {
			return {
				accounts: []
			}
		},
		onLoad() {
			_self=this
			_self.loadAccounts()
		},
		methods: {
			changeAcount(id) {
				console.log("change" +id)
				uni.request({
					url: this.api+'/credentials/accounts/'+id,
					method: 'POST',
					header: {
						"Authorization": "Bearer " + _self.getToken()
					},
					complete() {
						_self.loadAccounts()
					}										
				});
			},
			loadAccounts(){
				console.log("loadAccounts")
				uni.request({
					url: this.api+'/credentials/accounts',
					method: 'GET',
					header: {
						"Authorization": "Bearer " + _self.getToken()
					},
					success: res => {
						console.log("loadAccounts Resp")
						console.log(res.data.data)
						_self.accounts=res.data.data
					}					
				});
			}
		}
	}
</script>

<style>
	/* 	view{
		border: #000000 1px solid;
	} */

	.my-content {
		background-color: #F1F1F1;
		min-height: 70vh;
	}

	.platform {
		padding-left: 30upx;
		color: #004085;
	}
</style>
